package com.wise.service.cms.content.articlecommon;

import com.wise.entities.content.ArticleCommon;
import com.wise.framework.dao.SqlSelect;
import com.wise.framework.daomodel.DaoPageList;
import com.wise.framework.restful.PageResultList;
import com.wise.summer.v1.cms.content.articlecommons.ListArticleCommons;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;
import org.summerframework.model.SummerService;
import org.summerframework.model.SummerServiceBean;

@Service
@SummerService
public class ListArticleCommonsService implements SummerServiceBean<ListArticleCommons> {
    @Override
    public void sum(ListArticleCommons model) {
        SqlSelect sql = SqlSelect.selec("*")
                .fromClassName(ArticleCommon.class)
                .like(!StringUtils.isEmpty(model.getTitle()), ArticleCommon._title, "%" + model.getTitle() + "%")
//                .eq(!StringUtils.isEmpty(model.getColumnId()), ArticleCommon._columnId, model.getColumnId())
                .eq(model.getState() != null, ArticleCommon._state, model.getState())
                .eq(model.getIsApproval() != null, "is_approval", model.getIsApproval())
                .eqLang(ArticleCommon._lang)
                .order_by("id desc")
                .order_by(ArticleCommon._sort);

        PageResultList<ArticleCommon> pageResultList = DaoPageList.s(ArticleCommon.class, sql, model.getStart(), model.getLimit());

        model.setSummerResult(pageResultList);
    }

    /**
     * 查询栏目数据
     */
//    private List<ArticleCommonColumn> findColumn(List list){
//        SqlSelect sqlSelect = SqlSelect.selec("*");
//        sqlSelect.fromClassName(ArticleCommonColumn.class);
//        sqlSelect.in("id",list);
//        List<ArticleCommonColumn> articleColumns = DaoList.s(ArticleCommonColumn.class,sqlSelect);
//        return articleColumns;
//    }
}
